import { ComponentProps } from 'react';
import { isVoid, toNumber } from 'utils';
// type SelectProps = ComponentProps<typeof isVoid>;

interface IdSelectProps {
  value: number | string | undefined | null;
  onChang?: (value?: number) => void;
  options?: {
    name: string; id: number
  }[];
  defaultOptionName?: string;
}


export const IdSelect = ({ value, onChang, options, defaultOptionName }: IdSelectProps) => {
  return (
    <select value={toNumber(value)} onChange={(evt) => onChang?.(toNumber(evt.target.value) || undefined)}>
      {defaultOptionName ? (<option value={0}>{defaultOptionName}</option>) : null}
      {options?.map((option) => (<option value={option.id} key={option.id}>{option.name}</option>))}
    </select>
  );
}